<script>

/**
 * Orders Component
 */
export default {
  data() {
    return {
      ordersData: [
        {
          name: "policy_record",
          fieldNum: "8",
          dataNum: "83,423",
          storageCapacity: "10.4",
          createTime: "2017/5/17",
        },{
          name: "article_banner",
          fieldNum: "20",
          dataNum: "343,243",
          storageCapacity: "76.3",
          createTime: "2017/6/22",
        },{
          name: "article_record",
          fieldNum: "21",
          dataNum: "2,132,321",
          storageCapacity: "44.2",
          createTime: "2018/5/17",
        },{
          name: "bid_banner",
          fieldNum: "34",
          dataNum: "333,216",
          storageCapacity: "45.6",
          createTime: "2018/7/12",
        },{
          name: "bid_data",
          fieldNum: "45",
          dataNum: "3,453,453",
          storageCapacity: "55.1",
          createTime: "2019/5/7",
        },{
          name: "bid_record",
          fieldNum: "23",
          dataNum: "765,432",
          storageCapacity: "223.8",
          createTime: "2020/5/17",
        },{
          name: "biddingunit_basedata",
          fieldNum: "45",
          dataNum: "887,543",
          storageCapacity: "223.8",
          createTime: "2020/5/17",
        },{
          name: "biddingunit_basedata_spider",
          fieldNum: "21",
          dataNum: "6,554,343",
          storageCapacity: "34.3",
          createTime: "2020/6/22",
        },{
          name: "biddingunit_bid_data",
          fieldNum: "23",
          dataNum: "998,631",
          storageCapacity: "567.9",
          createTime: "2020/8/17",
        },{
          name: "data_business_dictionary",
          fieldNum: "41",
          dataNum: "324,333,221",
          storageCapacity: "452.1",
          createTime: "2020/9/19",
        }
      ],
      totalRows: 100,
      currentPage: 1,
      perPage: 10,
      fields: [
        { key: "name", label: "数据表名称" },
        { key: "fieldNum", label: "表字段数量" },
        { key: "dataNum", label: "表数据量(条)" },
        { key: "storageCapacity", label: "存储容量(MB)" },
        { key: "createTime", label: "创建时间" },
        { key: "viewDetail", label: "查看详情" },
      ],
    };
  },
  watch: {
    "currentPage": {
      handler(){
        console.log("触发分页");
      }
    }
  },
  methods: {
    /**
     * Search the table data with search input
     */
    onFiltered(filteredItems) {
      // Trigger pagination to update the number of buttons/pages due to filtering
      this.totalRows = filteredItems.length;
      this.currentPage = 1;
    },
    // 种子详情
    seedDetail(row){
      console.log(row);
      this.$router.push('/spider/siteDetail')
    },
    toadd(){
      // this.$router.push('/datahouse/addExample')
      let routeUrl = this.$router.resolve({
        path: '/datahouse/addExample'
      });
      window.open(routeUrl.href, '_blank');
    },
    toaddSurface(){
      let routeUrl = this.$router.resolve({
        path: '/datahouse/addSurface'
      });
      window.open(routeUrl.href, '_blank');
    },
    toDataField(){
      this.$router.push('/datahouse/dataField')
    },
    toDataDetail(){
      this.$router.push('/datahouse/dataDetail')
    }
  }
};
</script>

<template>
  <div>
    <!-- 搜索 -->
    <div class="search-box">
      <div>一共有 <span style="color:#3444c1;">20</span> 张数据表</div>
      <div>
        <b-dropdown dropup variant="secondary" class="butn">
          <template slot="button-content">
            <i class="ri-add-line align-middle" style="font-size: 1rem;"></i>
            <span style="margin:0 20px 0 6px;">数据管理</span>
            <i class="mdi mdi-chevron-up"></i>
          </template>
          <b-dropdown-item-button @click="toaddSurface">创建数据表</b-dropdown-item-button>
          <b-dropdown-item-button @click="toadd">创建数据实例</b-dropdown-item-button>
        </b-dropdown>
      </div>
    </div>
    <div class="table-responsive">
      <b-table
        class="table-centered"
        :items="ordersData"
        :fields="fields"
        responsive="sm"
        :per-page="perPage"
        :current-page="1"
        thead-class="thead-light"
        @filtered="onFiltered"
      >
        
        <template v-slot:cell(viewDetail)>
          <span @click="toDataField" style="cursor: pointer;">数据字段</span>
          <span style="margin:0 3px;">|</span>
          <span @click="toDataDetail" style="cursor: pointer;">数据详情</span>
          <span style="margin:0 3px;">|</span>
          <span style="cursor: pointer;">删除表</span>
        </template>
      </b-table>
    </div>
    <div class="row">
      <div class="col">
        <div class="dataTables_paginate paging_simple_numbers float-right">
          <ul class="pagination pagination-rounded mb-0">
            <!-- pagination -->
            <b-pagination v-model="currentPage" :total-rows="totalRows" :per-page="perPage"></b-pagination>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>
<style lang="scss" scoped>
.search {
  float: left;
  width: 300px;
  margin-top: 20px;
  margin-bottom: 20px;
}
.border-radius{
  border-radius: 0px;
  border-bottom-left-radius: 30px;
  border-top-left-radius: 30px;
}
.right-dropdown{
  ::v-deep .btn{
    font-size: 0;
    border-radius: 0px;
    padding: 0.47rem 0.5rem;
    border-bottom-right-radius: 30px;
    border-top-right-radius: 30px;
    i{
      font-size: 0.9rem;
      vertical-align: middle;
    }
  }
}
.butn{
  ::v-deep .btn{
    background-color: #252b3b;
    border-color: #252b3b;
    border-radius: 30px;
    display: flex;
    align-items: center;
  }
  ::v-deep .btn-secondary.focus {
    box-shadow: 0 0 0 0.15rem rgb(37 40 58 / 50%);
  }
}
.search-box{
  margin-top: 12px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.table-centered{
  ::v-deep thead,::v-deep tbody{
    tr{
      th:last-child,td:last-child{
        text-align: right;
      }
    }
  }
}
</style>

